namespace cframework {
using UnityEngine;
using Newtonsoft.Json;
#if UNITY_EDITOR
using UnityEditor;
#endif

public enum Platform
{
	unknown,
	ios,
	android,
	win,
	win64,
	OSXUniversal,
	WebGL,
}

public enum SubPlatform
{
	none,
	wechat,
}

public static class PlatformEx
{
	public static Platform getPlatform()
	{
		return UnityEngine.Application.platform.getPlatform();
	}

	public static Platform getPlatform(this UnityEngine.RuntimePlatform platform)
	{
		return getPlatform(platform, System.IntPtr.Size);
	}

	public static Platform getPlatform(this UnityEngine.RuntimePlatform platform, int intPtrSize)
	{
		switch(platform)
		{
			case UnityEngine.RuntimePlatform.IPhonePlayer:
			{
				return Platform.ios;
			}
			case UnityEngine.RuntimePlatform.Android:
			{
				return Platform.android;
			}
			case UnityEngine.RuntimePlatform.WindowsPlayer:
			{
				if(intPtrSize == 8)
				{
					return Platform.win64;
				}
				else if(intPtrSize == 4)
				{
					return Platform.win;
				}
				else
				{
					return Platform.unknown;
				}
			}
			case UnityEngine.RuntimePlatform.OSXPlayer:
			{
				return Platform.OSXUniversal;
			}
			case UnityEngine.RuntimePlatform.WebGLPlayer:
			{
				return Platform.WebGL;
			}
			default:
			{
#if UNITY_IOS
			return Platform.ios;
#elif UNITY_ANDROID
			return Platform.android;
#elif UNITY_WEBGL
			return Platform.WebGL;
#else
			if(Application.isEditor)
			{
				// return Platform.android;
			}
			return Platform.unknown;
#endif
			}
		}
	}

#if UNITY_EDITOR
	public static BuildTarget ToBuildTarget(this Platform platform)
	{
		switch(platform)
		{
			case Platform.ios:
			{
				return BuildTarget.iOS;
			}
			case Platform.android:
			{
				return BuildTarget.Android;
			}
			case Platform.win:
			{
				return BuildTarget.StandaloneWindows;
			}
			case Platform.win64:
			{
				return BuildTarget.StandaloneWindows64;
			}
			case Platform.OSXUniversal:
			{
				return BuildTarget.StandaloneOSX;
			}
			case Platform.WebGL:
			{
				return BuildTarget.WebGL;
			}
		}

		return BuildTarget.tvOS;
	}
#endif
}


}